
(deftemplate data
    (slot value)
    (slot time) 
    )
(deftemplate request
    (slot dataId)
    (slot initialTime)
    (slot finalTime) 
    )
(deftemplate maximum
    (slot max)
   
    )

(load-function Maximum.Maximum)


(defrule get
    ?f<-(request (dataId ?dataId) (initialTime ?initialTime) (finalTime ?finalTime))
    =>
    (printout t "request for server" crlf)
    (Maximum ?dataId ?initialTime ?finalTime)
    (retract ?f)
    (facts)
)
(defrule calc
    ?f1<-(data (value ?t) (time ?d))
    ?f2<-(maximum (max ?m& : ((<= ?m ?t))))
    =>
    (modify ?f2 ( max ?t)
    (retract ?f1)  
)
    )
(defrule last
    (declare (salience -1))
    ?f<-(maximum (max ?m))
    =>
    (assert (result ?m))
    (retract ?f)
)
(assert (maximum (max -1)))
(assert (request (dataId 1) (initialTime "10.05.10") (finalTime "12.05.10")))
(run)